package com.gkj.gulimall.product.javabase.internet;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTest {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1",9000);
            BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
            BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));//接收服务器发来的数据
            String readLine = sin.readLine();
            while(!(readLine).equals("bye")){
                printWriter.println(readLine);
                printWriter.flush();
                System.out.println("Client say"+readLine);

                System.out.println("Server say"+is.readLine());

                readLine = sin.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

class SocketServerTest{
    public static void main(String[] args) {
        try {
            ServerSocket socket = new ServerSocket(9000);
            Socket accept = socket.accept();//接收客户端的请求
            BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter os = new PrintWriter(accept.getOutputStream());
            String readLine = sin.readLine();
            while(!readLine.equals("bye")){
                
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
